import {defineConfig, loadEnv} from 'vite'
import vue from '@vitejs/plugin-vue'
import vitePluginImport from 'vite-plugin-babel-import'
import path from 'path'

const baseUrl = {
  development: './',
  staging: './',
  production: './'
}

// https://vitejs.dev/config/
export default defineConfig(({ mode, command }) => {
  const env = loadEnv(mode, process.cwd())
  return {
    plugins: [
      vue(),
      vitePluginImport([
        {
          libraryName: 'element-plus',
          libraryDirectory: 'es',
          style(name) {
            return `element-plus/lib/theme-chalk/${name}.css`;
          },
        }
      ])
    ],
    base: baseUrl[mode],
    resolve: {
      alias: {
        '~': path.resolve(__dirname, './'),
        '@': path.resolve(__dirname, 'src')
      }
    },
    server: {
      proxy: {
        '/api': {
          // target: 'http://backend-api-02.newbee.ltd/manage-api/v1',
          target: env.VITE_APP_BASE_API,
          changeOrigin: true,
          rewrite: path => path.replace(/^\/api/, '')
        }
      }
    }
  }
})